<?php
namespace Modules\Shop\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Shop\Entities\Article;
use Modules\Shop\Entities\Category;
use Modules\Shop\Http\Requests\ArticleRequest;
class ArticleController extends Controller
{
    //显示列表
    public function index()
    {
        //获取模块菜单列表,传递的参数是不返回的模块,不传递返回所有模块
        //dd(\HDModule::getModulesLists());
        //dd(\HDModule::getMenuByModule());
        $data = Article::paginate(10);
        return view('shop::article.index', compact('data'));
    }

    //创建视图
    public function create(Article $article)
    {
        //获取所有分类数据
        $categorys=Category::getTreeCategory();
        return view('shop::article.create',compact('article','categorys'));
    }

    //保存数据
    public function store(ArticleRequest $request,Article $article)
    {

        $article->fill($request->all());
        $article->save();
        return redirect('/shop/article')->with('success', '保存成功');
    }

    //显示记录
    public function show(Article $field)
    {
        return view('shop::article.show', compact('field'));
    }

    //编辑视图
    public function edit(Article $article)
    {
         $categorys=Category::getTreeCategory();
        return view('shop::article.edit',compact('article','categorys'));
    }

    //更新数据
    public function update(ArticleRequest $request, Article $article)
    {
        $article->update($request->all());
        return redirect('/shop/article')->with('success','更新成功');
    }

    //删除模型
    public function destroy(Article $article)
    {
        $article->delete();
        return redirect('shop/article')->with('success','删除成功');
    }
}
